﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>EditAdmin</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="~/layuiadmin/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    <form onsubmit="return false" method="post" class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
        <div class="layui-form-item layui-hide">
            <label class="layui-form-label">Id</label>
            <div class="layui-input-inline">
                <input type="text" name="Id" value="@Model.User.Id" lay-verify="required" placeholder="Id" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="userName" value="@Model.User.UserName" lay-verify="required" placeholder="请输入用户名" autocomplete="off" readonly class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-inline">
                <input type="text" name="nickName" value="@Model.User.NickName" lay-verify="nickname" placeholder="请输入昵称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-inline">
                <select name="roleId" lay-filter="required">
                    @{
                        foreach (var role in Model.RoleList)
                        {
                            if (role.Id == Model.User.RoleId)
                            {
                                <option value="@role.Id" selected="">@role.RoleName</option>
                            }
                            else
                            {
                                <option value="@role.Id">@role.RoleName</option>
                            }
                        }
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" readonly value="@Model.User.Password" placeholder="请输入密码" autocomplete="off" class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <button class="layui-btn" lay-submit lay-filter="edit">
                确认
            </button>
        </div>
    </form>
    <script src="~/layuiadmin//layui/layui.js"></script>
    <script>
        layui.config({
            base: '../layuiadmin/'
        }).extend({
            index: 'lib/index'
        }).use(['index', 'form', 'set'], function () {
            var $ = layui.$
                , layer = layui.layer
                , form = layui.form;

            form.on('submit(edit)', function (data) {
                $.ajax({
                    type: "post",
                    url: "/Account/EditUser?Id=" + data.field.Id,
                    dataType: 'json',
                    data: data.field,
                    success: function (result) {
                        if (result.code == 0) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000
                            }, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                });
                return false;
            });
        });
    </script>
</body>
</html>